﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuanLyDiem.models;
using DevExpress.XtraEditors.Repository;
namespace QuanLyDiem.Controllers
{
    public class C_ChuyenNganh
    {
        public static void LoadDataSource(LookUpEdit lookUpEdit, Context db = null)
        {
            if (db == null) db = new Context();

            lookUpEdit.Properties.Columns.Clear();

            lookUpEdit.Properties.DataSource = db.ChuyenNganhs.OrderBy(o => o.Chuyen_nganh).ToList();

            lookUpEdit.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Chuyen_nganh", "Chuyên ngành"));
            lookUpEdit.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFit;

            lookUpEdit.Properties.DisplayMember = "Chuyen_nganh";
            lookUpEdit.Properties.ValueMember = "ID_chuyen_nganh";
            lookUpEdit.Properties.NullText = "";
            lookUpEdit.ToolTip = lookUpEdit.Properties.NullValuePrompt = "Chọn chuyên ngành";

            lookUpEdit.Properties.NullValuePromptShowForEmptyValue = true;
            lookUpEdit.Properties.AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.True;
            lookUpEdit.ItemIndex = 0;
        }
        public static void LoadDataSource(RepositoryItemLookUpEdit lookUpedit, Context db = null)
        {
            if (db == null) db = new Context();
            lookUpedit.Columns.Clear();
            lookUpedit.DataSource = db.ChuyenNganhs.OrderBy(a => a.Chuyen_nganh).ToList();
            lookUpedit.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Chuyen_nganh", "Chuyên ngành"));
            lookUpedit.DisplayMember = "Chuyen_nganh";
            lookUpedit.ValueMember = "ID_chuyen_nganh";
            lookUpedit.NullText = string.Empty;
            lookUpedit.NullValuePrompt = string.Empty;
            lookUpedit.NullValuePromptShowForEmptyValue = true;
            lookUpedit.AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.False;
        }
    }
}
